package offer;

/**
 * @Author SSK
 * @Date Created in 19:36 2019/8/4
 * @Description 数组中重复的数字
 * @Version 1.0
 */
public class T51 {
    public boolean duplicate(int numbers[],int length,int [] duplication) {
        if (numbers==null) {
            return false;
        }
        if (numbers.length<=1) {
            duplication[0] = numbers[0];
            return true;
        }
        for (int i = 0; i < numbers.length; i++) {
                if (numbers[i]==i) {
                    continue;
                }
                if (numbers[numbers[i]]!=numbers[i]) {
                int temp = numbers[i];
                numbers[i] = numbers[numbers[i]];
                numbers[temp] = temp;
                i--;
            }else {
                duplication[0] = numbers[0];
                return true;
            }
        }
        return false;

    }
    public static void main ( String[] args) {

        new T51().duplicate(new int[]{2,1,3,1,4},5,new int[1]);
    }
}
